<!DOCTYPE html >
<html>
<head>
    <link rel="stylesheet" href="demos.css" type="text/css" media="screen" />
    
    <script src="../libraries/RGraph.common.core.js" ></script>
    <script src="../libraries/RGraph.common.dynamic.js" ></script>
    <script src="../libraries/RGraph.common.effects.js" ></script>
    <script src="../libraries/RGraph.drawing.text.js" ></script>
    <script src="../libraries/RGraph.bar.js" ></script>
    
    <title>RGraph demo: A Bar chart capable of drilldown</title>
    
    <meta name="robots" content="noindex,nofollow" />
    <meta name="description" content="A Bar chart that's capable of drilldown when you click on a bar" />
    
</head>
<body>

    <!-- Share buttons -->
    <p style="float: right">
        <script>
            document.write('<a href="" target="_blank" onclick="window.open(\'https://www.facebook.com/sharer/sharer.php?u=http://www.rgraph.net' + location.pathname + '\', null, \'top=50,left=50,width=600,height=368\'); return false"><img src="../images/facebook-large.png" width="200" height="43" alt="Share on Facebook" border="0" title="Visit the RGraph Facebook page" id="facebook_link" /></a>&nbsp;');
            document.write('<a href="https://twitter.com/_rgraph" target="_blank" onclick="window.open(\'https://twitter.com/intent/tweet?text=Check%20out%20this%20demo%20of%20RGraph:%202D/3D%20JavaScript%20charts%20-%20Free%20and%20Open%20Source%20http://www.rgraph.net' + location.pathname + '\', null, \'top=50,left=50,width=700,height=400\'); return false"><img src="../images/twitter-large.png" width="200" height="43" alt="Share on Twitter" border="0" title="Mention RGraph on Twitter" id="twitter_link" /></a>');
        </script>
    </p>


    <h1>A Bar chart capable of drilldown</h1>

    <canvas id="cvs" width="650" height="250">[No canvas support]</canvas><br />
    
    <button id="butBack">Show the overview chart</button>
    
    <script>
        window.onload = function ()
        {
            var ca = document.getElementById("cvs");
            var data           = [15,14,12,18,16,13];
            var data_drilldown = [];

            /**
            * The drilldown data - the order corresponds to that of the labels
            */
            data_drilldown.push([2,3,1,2,3,1,3]);
            data_drilldown.push([2,2,2,1,2,2,3]);
            data_drilldown.push([1,1,1,2,3,2,2]);
            data_drilldown.push([3,3,3,2,3,3,1]);
            data_drilldown.push([4,3,1,1,3,2,2]);
            data_drilldown.push([3,2,2,2,3,1,0]);

            var labels = ['John','Fred','Luis','Kevin','Lola','June']

            var bar = drawMainChart();
            
            /**
            * Draws the main chart
            */
            function drawMainChart ()
            {
                RGraph.reset(ca);

                var bar = new RGraph.Bar({
                    id: 'cvs',
                    data: data,
                    options: {
                        labels: labels,
                        bevel: true,
                        title: 'The whole teams statistics for sales of widgets',
                        backgroundGridAutofitNumvlines: data.length,
                        strokestyle:'rgba(0,0,0,0)',
                        textAccessible: true,
                        shadow: true
                    }
                }).fadeIn();


            
                /**
                * When a bar is clicked show a more detailed breakdown
                */
                bar.onclick = function (e, shape)
                {
                    var obj = e.target.__object__;
                    var ca  = obj.canvas;
                    var idx = shape.index;



                    /**
                    * Slide the old bar out
                    */
                    obj.fadeOut(null, function ()
                    {
                        RGraph.reset(ca);
    
                        var bar = new RGraph.Bar({
                            id: 'cvs',
                            data: data_drilldown[idx],
                            options: {
                                labels: ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],
                                bevel: true,
                                strokestyle: 'rgba(0,0,0,0)',
                                title: 'Specific statistics for: ' + labels[idx],
                                backgroundGridAutofitNumvlines: 7,
                                textAccessible: true
                            }
                        }).fadeIn();
                    });
                }
                
                /**
                * The onmousemove event to change the cursor
                */
                bar.onmousemove = function (e, shape)
                {
                    return true;
                }
                
                return bar;
            }
            
            document.getElementById("butBack").onclick = function (e)
            {
                var obj = ca.__object__;

                obj.fadeOut(null,function ()
                {
                    var bar = drawMainChart();
                });
            }
        };
    </script>








    <p></p>

    This goes in the documents header:
    <pre class="code">
&lt;script src="RGraph.common.core.js"&gt;&lt;/script&gt;
&lt;script src="RGraph.common.effects.js"&gt;&lt;/script&gt;
&lt;script src="RGraph.common.dynamic.js"&gt;&lt;/script&gt;
&lt;script src="RGraph.drawing.text.js"&gt;&lt;/script&gt;
&lt;script src="RGraph.bar.js"&gt;&lt;/script&gt;
</pre>
    
    Put this where you want the chart to show up:
    <pre class="code">
&lt;canvas id="cvs" width="600" height="250"&gt;
    [No canvas support]
&lt;/canvas&gt;
</pre>

    This is the code that generates the chart:
    <pre class="code">
&lt;script&gt;
    window.onload = function ()
    {
        var ca = document.getElementById("cvs");
        var data           = [15,14,12,18,16,13];
        var data_drilldown = [];

        <span>/**
        * The drilldown data - the order corresponds to that of the labels
        */</span>
        data_drilldown.push([2,3,1,2,3,1,3]);
        data_drilldown.push([2,2,2,1,2,2,3]);
        data_drilldown.push([1,1,1,2,3,2,2]);
        data_drilldown.push([3,3,3,2,3,3,1]);
        data_drilldown.push([4,3,1,1,3,2,2]);
        data_drilldown.push([3,2,2,2,3,1,0]);

        var labels = ['John','Fred','Luis','Kevin','Lola','June']

        var bar = drawMainChart();
        
        <span>/**
        * Draws the main chart
        */</span>
        function drawMainChart ()
        {
            RGraph.reset(ca);

            var bar = new RGraph.Bar({
                id: 'cvs',
                data: data,
                options: {
                    labels: labels,
                    bevel: !RGraph.ISOLD,
                    title: 'The whole teams statistics for sales of widgets',
                    backgroundGridAutofitNumvlines: data.length,
                    strokestyle:'rgba(0,0,0,0)',
                    textAccessible: true,
                    shadow: true
                }
            }).fadeIn();


        
            <span>/**
            * When a bar is clicked show a more detailed breakdown
            */</span>
            bar.onclick = function (e, shape)
            {
                var obj = e.target.__object__;
                var ca  = obj.canvas;
                var idx = shape.index;



                <span>/**
                * Slide the old bar out
                */</span>
                obj.fadeOut(null, function ()
                {
                    RGraph.reset(ca);

                    var bar = new RGraph.Bar({
                        id: 'cvs',
                        data: data_drilldown[idx],
                        options: {
                            labels: ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],
                            bevel: true,
                            strokestyle: 'rgba(0,0,0,0)',
                            title: 'Specific statistics for: ' + labels[idx],
                            backgroundGridAutofitNumvlines: 7,
                            textAccessible: true
                        }
                    }).fadeIn();
                });
            }
            
            <span>/**
            * The onmousemove event to change the cursor
            */</span>
            bar.onmousemove = function (e, shape)
            {
                return true;
            }
            
            return bar;
        }
        
        document.getElementById("butBack").onclick = function (e)
        {
            var obj = ca.__object__;

            obj.fadeOut(null,function ()
            {
                var bar = drawMainChart();
            });
        }
    };
&lt;/script&gt;
</pre>


    

    <p>
        <a href="./">&laquo; Back</a>
    </p>

</body>
</html>